/*************************************************************************
* filename: pushrod_port.c
* Abstract: The port setting of pushrod
* describe: The port setting of pushrod
* author: 	lkp
* version: 	v1.0
* date: 	2019-10-23
*************************************************************************/
/** 推杆相关操作*/

/*
*   自定义推杆操作，以及端口初始化。
*   超过推杆数量的操作可以不用定义。
*/

/**********************************************************************
*                             PORT_INIT                              *
**********************************************************************/
#include "pushrod_bsp.h"
#include "user_cfg.h"
#include "app.h"

#define PUSH1_A_PORT                GPIOF
#define PUSH1_A_PIN                 GPIO_PIN_2
#define PUSH1_B_PORT                GPIOB
#define PUSH1_B_PIN                 GPIO_PIN_3

#define PUSH2_A_PORT                GPIOA
#define PUSH2_A_PIN                 GPIO_PIN_12
#define PUSH2_B_PORT                GPIOA
#define PUSH2_B_PIN                 GPIO_PIN_15

#define PUSH3_A_PORT                GPIOA
#define PUSH3_A_PIN                 GPIO_PIN_8
#define PUSH3_B_PORT                GPIOA
#define PUSH3_B_PIN                 GPIO_PIN_11





void Push_Port_Init(void)
{

	GPIO_InitType GPIO_InitStructure;
	RCC_EnableAPB2PeriphClk(RCC_APB2_PERIPH_GPIOA, ENABLE);
	RCC_EnableAPB2PeriphClk(RCC_APB2_PERIPH_GPIOB, ENABLE);
	RCC_EnableAPB2PeriphClk(RCC_APB2_PERIPH_GPIOF, ENABLE);

	GPIO_InitStruct(&GPIO_InitStructure);

	GPIO_InitStructure.Pin = PUSH2_A_PIN | PUSH2_B_PIN | PUSH3_A_PIN | PUSH3_B_PIN;
	GPIO_InitStructure.GPIO_Mode = GPIO_MODE_OUTPUT_PP;
	GPIO_InitStructure.GPIO_Current = GPIO_DC_LOW;
	GPIO_InitPeripheral(GPIOA, &GPIO_InitStructure);

	GPIO_InitStructure.Pin = PUSH1_B_PIN;
	GPIO_InitStructure.GPIO_Mode = GPIO_MODE_OUTPUT_PP;
	GPIO_InitStructure.GPIO_Current = GPIO_DC_LOW;
	GPIO_InitPeripheral(GPIOB, &GPIO_InitStructure);

	GPIO_InitStructure.Pin = GPIO_PIN_2;
	GPIO_InitStructure.GPIO_Mode = GPIO_MODE_OUTPUT_PP;
	GPIO_InitStructure.GPIO_Current = GPIO_DC_LOW;
	GPIO_InitPeripheral(GPIOF, &GPIO_InitStructure);

}

/**********************************************************************
*                          PUSHROD_OPERATION                           *
**********************************************************************/
void Pushrod_Open(pushrod_u16_t dev)
{
    //app_para.pushrod_flag = TRUE;
    switch(dev) {

        case PUSHROD_DEV1: {
            /*在此添加Push1打开的代码*/
            GPIO_SetBits(PUSH1_A_PORT, PUSH1_A_PIN);
            GPIO_ResetBits(PUSH1_B_PORT, PUSH1_B_PIN);
            /*************/
            break;
        }
        case PUSHROD_DEV2: {
            /*在此添加Push2打开的代码*/
            GPIO_SetBits(PUSH2_A_PORT, PUSH2_A_PIN);
            GPIO_ResetBits(PUSH2_B_PORT, PUSH2_B_PIN);
            /*************/
            break;
        }
        case PUSHROD_DEV3: {
            /*在此添加Push3打开的代码*/
            GPIO_SetBits(PUSH3_A_PORT, PUSH3_A_PIN);
            GPIO_ResetBits(PUSH3_B_PORT, PUSH3_B_PIN);
            /*************/
            break;
        }
        case PUSHROD_DEV4: {
            /*在此添加Push4打开的代码*/


            /*************/
            break;
        }
        case PUSHROD_DEV5: {
            /*在此添加Push5打开的代码*/

            /*************/
            break;
        }
        case PUSHROD_DEV6: {
            /*在此添加Push6打开的代码*/

            /*************/
            break;
        };

        /*超过6个推杆可自行添加case*/

        /*************/
        default:
            break;
    }
}

void Pushrod_Close(pushrod_u16_t dev)
{
    //app_para.pushrod_flag = TRUE;
    switch(dev) {

        case PUSHROD_DEV1: {
            /*在此添加Push1收回的代码*/
            GPIO_SetBits(PUSH1_B_PORT, PUSH1_B_PIN);
            GPIO_ResetBits(PUSH1_A_PORT, PUSH1_A_PIN);
            /*************/
            break;
        }
        case PUSHROD_DEV2: {
            /*在此添加Push2收回的代码*/
            GPIO_SetBits(PUSH2_B_PORT, PUSH2_B_PIN);
            GPIO_ResetBits(PUSH2_A_PORT, PUSH2_A_PIN);
            /*************/
            break;
        }
        case PUSHROD_DEV3: {
            /*在此添加Push3收回的代码*/
            GPIO_SetBits(PUSH3_B_PORT, PUSH3_B_PIN);
            GPIO_ResetBits(PUSH3_A_PORT, PUSH3_A_PIN);
            /*************/
            break;
        }
        case PUSHROD_DEV4: {
            /*在此添加Push4收回的代码*/

            /*************/
            break;
        };
        case PUSHROD_DEV5: {
            /*在此添加Push5收回的代码*/

            /*************/
            break;
        }
        case PUSHROD_DEV6: {
            /*在此添加Push6收回代码*/

            /*************/
            break;
        }
        /*超过6个推杆可自行添加case*/

        /*************/
        default:
            break;
    }
}

void Pushrod_Stop(pushrod_u16_t dev)
{
    switch(dev) {
        case PUSHROD_DEV1: {
            /*在此添加Push1停止的代码*/
            GPIO_ResetBits(PUSH1_A_PORT, PUSH1_A_PIN);
            GPIO_ResetBits(PUSH1_B_PORT, PUSH1_B_PIN);
            /*************/
            break;
        }
        case PUSHROD_DEV2: {
            /*在此添加Push2停止的代码*/
            GPIO_ResetBits(PUSH2_A_PORT, PUSH2_A_PIN);
            GPIO_ResetBits(PUSH2_B_PORT, PUSH2_B_PIN);
            /*************/
            break;
        }
        case PUSHROD_DEV3: {
            /*在此添加Push3停止的代码*/
            GPIO_ResetBits(PUSH3_A_PORT, PUSH3_A_PIN);
            GPIO_ResetBits(PUSH3_B_PORT, PUSH3_B_PIN);
            /*************/
            break;
        }
        case PUSHROD_DEV4: {
            /*在此添加Push4停止的代码*/


            /*************/
            break;
        };
        case PUSHROD_DEV5: {
            /*在此添加Push5停止的代码*/

            /*************/
            break;
        };
        case PUSHROD_DEV6: {
            /*在此添加Push6停止的代码*/

            /*************/
            break;
        }
        /*超过6个推杆可自行添加case*/

        /*************/

        default:
            break;
    }
}

pushrod_u16_t pushrod_clk;
pushrod_u16_t Pushrod_Clk_Get(void)
{
    /** 时钟获取 */
    pushrod_u16_t pclk;

    /** 在此添加代码 返回一个1ms的时钟 */

    /** example:   */
    /** extern unsigned long value;  // 在1ms定时器中递增value*/
    /** pclk = value; */
    pclk = pushrod_clk;
    /** ********************************/
    return (pclk);
}

